package ansi.servlet.registro_cuotas;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import ansi.modelo.Cuotas;

import ansi.negocio.GestionCuotas;
import ansi.util.Texto;



/**
 * Servlet implementation class ObtenerCuotasServlet
 */
@WebServlet("/ObtenerCuotas")
public class ObtenerCuotasServlet  extends HttpServlet{
	
	private static final long serialVersionUID = 1L;
    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ObtenerCuotasServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		editar(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		editar(request, response);
	}
	
	protected void editar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			String[] arrIdCuota			= request.getParameterValues("idCuota");
			GestionCuotas gestionCuotas	= new GestionCuotas();
			Cuotas cuotas		= null;
			if(arrIdCuota != null && arrIdCuota.length > 0) {
			cuotas	= gestionCuotas.obtener(Texto.getInt(arrIdCuota[0]));
				request.setAttribute("cuotas", cuotas);
			}
			RequestDispatcher rd	= request.getRequestDispatcher("ObtenerCuota.jsp");
			rd.forward(request, response);
		} catch(Exception ex) {
			ex.printStackTrace();
		}
	}

}
